package com.dreambreeze.service.impl;

import com.dreambreeze.common.bean.ResultBean;
import com.dreambreeze.dao.UserMapper;
import com.dreambreeze.pojo.User;
import com.dreambreeze.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @description:用户服务实现类
 * @auther: dream breeze
 * @date: 2019/07/22 19:26
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public ResultBean addOrUpdate(User user) {
        int userId = user.getUserId();
        int result;
        if(0 == userId){
            result = userMapper.insert(user);
        }else {
            result = userMapper.updateByPrimaryKey(user);
        }
        return result == 1 ? ResultBean.ok() : ResultBean.defeated();
    }

    @Override
    public ResultBean delete(User user) {
        return userMapper.delete(user) == 1 ? ResultBean.ok() : ResultBean.defeated();
    }

    @Override
    public ResultBean selectByUser(User user) {
        return ResultBean.ok(userMapper.selectByUser(user));
    }
}
